package com.leantech.android.browser.ui.browser.adapter

import android.view.LayoutInflater
import android.view.View
import com.cscj.android.repository.db.entity.HotSearchEntity
import com.leantech.android.browser.databinding.ItemMarqueeHotSearchBinding
import com.leantech.android.browser.utils.onThrottleClick
import com.stx.xmarqueeview.XMarqueeView
import com.stx.xmarqueeview.XMarqueeViewAdapter

class HotSearchMarqueeAdapter(
    private val callback: HotSearchMarqueeCallback
) : XMarqueeViewAdapter<HotSearchEntity>(emptyList()) {

    private lateinit var binding: ItemMarqueeHotSearchBinding

    override fun onCreateView(parent: XMarqueeView): View {
        binding =
            ItemMarqueeHotSearchBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return binding.root
    }

    override fun onBindView(parent: View?, view: View?, position: Int) {
        val item = mDatas?.getOrNull(position) ?: return
        binding.content.text = item.content
        binding.root.onThrottleClick {
            callback.onHotSearchItemClick(item, position)
        }
    }

    interface HotSearchMarqueeCallback {

        fun onHotSearchItemClick(item: HotSearchEntity, position: Int)
    }

}